﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SelfManagement.Database.Common
{
    public class EntityBase
    {
        public EntityBase()
        {
            Id = Guid.NewGuid().ToString();
            CreatedTime = DateTime.Now;
            UpdatedTime = DateTime.Now;
            CreatedBy = "系统";
            UpdatedBy = "系统";
        }

        public void SetUpdateInfo(string updateBy)
        {
            UpdatedBy = updateBy;
            UpdatedTime = DateTime.Now;
        }

        public void SetCreateInfo(string createBy)
        {
            CreatedBy = createBy;
            CreatedTime = DateTime.Now;
        }

        public void SetCreateAndUpdateInfo(string changeBy)
        {
            UpdatedBy = CreatedBy = changeBy;
            UpdatedTime = CreatedTime = DateTime.Now;
        }

        [Key]
        public string Id { get; set; }

        public bool IsDelete { get; set; } = false;

        [DataType(DataType.DateTime)]
        public DateTime CreatedTime { get; set; }

        [DataType(DataType.DateTime)]
        public DateTime UpdatedTime { get; set; }

        [Required, StringLength(50)]
        public string UpdatedBy { get; set; }

        [Required, StringLength(50)]
        public string CreatedBy { get; set; }
    }
}
